using System;
using System.Collections.Generic;
using System.IO;
using JsonFx.Json;
using UnityEngine;

public class PlaytomicFileSystem : IJsonFileSystem
{
	public PlaytomicFileSystem()
	{
		if (!PlaytomicCloud.IsLoaded)
		{
			UnityEngine.Debug.LogError("PlaytomicCloud is not loaded yet.");
		}
	}

	public string LoadContext(string key)
	{
		if (PlaytomicCloud.HasKey(key))
		{
			return JsonWriter.Serialize(PlaytomicCloud.ObjectForKey(key));
		}
		return null;
	}

	public void SaveContext(string key, string content)
	{
		if (PlayerPrefs.HasKey(key))
		{
			Dictionary<string, object> value = JsonReader.Deserialize<Dictionary<string, object>>(content);
			PlaytomicCloud.SetObject(key, value);
		}
	}

	public string Read(string path)
	{
		return File.ReadAllText(Application.dataPath + "/Data/text/" + path + ".txt");
	}

	public void Write(string path, string content)
	{
		UnityEngine.Debug.LogWarning("PlaytomicFileSystem.Write not Implemented");
	}
}
